package bg.tu.varna.pms.model.communication;

import java.io.Serializable;

import org.omg.CORBA.portable.ApplicationException;

import bg.tu.varna.pms.model.ChatRoom;

public final class ChatRoomMessage {
	public static enum ModificationType {
		AddUsers, RemoveUsers, CloseChatRoom
	}

	/**
	 * Only for group chat rooms
	 * 
	 * @author Gospodin Gospodinov
	 */
	public final static class Request implements Serializable {
		private static final long serialVersionUID = -3549297938721159021L;
		private final ChatRoom mChatRoom;

		public Request(ChatRoom chatRoom) throws ApplicationException {
			if (chatRoom.isGroupChat()) {
				mChatRoom = chatRoom;
			} else {
				throw new ApplicationException(
						"Personal chat rooms are not meant to be created.",
						null);
			}
		}

		public ChatRoom getChatRoom() {
			return mChatRoom;
		}
	}

	public final static class Response implements Serializable {
		private static final long serialVersionUID = -1839816440500506978L;
		private final ChatRoom mChatRoom;
		private final boolean mSuccess;

		public Response(ChatRoom chatRoom, boolean success) {
			mChatRoom = chatRoom;
			mSuccess = success;
		}

		public ChatRoom getChatRoom() {
			return mChatRoom;
		}

		public String getChatRoomID() {
			return mChatRoom.getID();
		}

		public boolean isSuccess() {
			return mSuccess;
		}
	}

	/**
	 * Add, remove username, close group
	 * 
	 * @author Gospodin Gospodinov
	 */
	public final static class Modification implements Serializable {
		private static final long serialVersionUID = -1152521014382601839L;
		private final String mChatRoomID;
		private final ModificationType mType;
		private final String[] mUsernames;

		public Modification(String chatRoomID, ModificationType type,
				String... usernames) {
			if (ChatRoom.isGroupChat(chatRoomID)) {
				mChatRoomID = chatRoomID;
				mType = type;
				if (mType != ModificationType.CloseChatRoom) {
					mUsernames = usernames;
				} else {
					mUsernames = null;
				}
			} else {
				throw new IllegalArgumentException("chatRoomID");
			}
		}

		public String getChatRoomID() {
			return mChatRoomID;
		}

		public ModificationType getType() {
			return mType;
		}

		public String[] getUsernames() {
			return mUsernames;
		}
	}
}
